package yxk.workflow;

import com.alibaba.fastjson.JSONObject;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.util.StringUtils;
import kd.bos.workflow.api.AgentExecution;
import kd.bos.workflow.component.approvalrecord.IApprovalRecordItem;
import kd.bos.workflow.engine.extitf.IWorkflowPlugin;
import yxk.list.odc.homs.util.OnboardUtil;

import java.util.*;

/*
 *
 *
 *@author lqh
 *@date 2023/9/24
 *
 */
public class TurnPositiveWorkPlugin implements IWorkflowPlugin {
    private OnboardUtil onboardUtil=new OnboardUtil();
    @Override
    public void notify(AgentExecution execution) {
        IWorkflowPlugin.super.notify(execution);
        if (execution.getBusinessKey() != null) {

            String businessKey = execution.getBusinessKey();

            if (!StringUtils.isEmpty(businessKey)) {
                DynamicObject hdm_regbasebill = BusinessDataServiceHelper.loadSingle(businessKey, "hdm_regbasebill");
                String regstatus = hdm_regbasebill.getString("regstatus");
                String auditstatus = hdm_regbasebill.getString("auditstatus");
                if ("1040".equals(regstatus) && "C".equals(auditstatus)) {
                    JSONObject params = new JSONObject();
                    String number = hdm_regbasebill.getString("person.number");// number工号
                    params.put("candidatenumber", number);
                    params.put("status", 1);
                    Date effectdate = hdm_regbasebill.getDate("effectdate");
                    if (effectdate == null || "".equals(effectdate)) {
                        params.put("correctedAt", OnboardUtil.formatDateNow());
                    } else {
                        params.put("correctedAt", OnboardUtil.formatDate(effectdate));
                    }
                    String token = onboardUtil.getZhaoPinToken();
                    params.put("token", token);
                    Boolean corrected = onboardUtil.getCorrected(token,params.toString(),number);
                    System.out.println(corrected);
                }
            }

        }
    }
}
